package com.example.s03themeleaf.controller;

import com.example.s03themeleaf.model.User;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.ArrayList;
import java.util.List;

@Controller
public class HelloController {

    @GetMapping("/test1")
    public String test1(Model m)
    {
        m.addAttribute("message","Hello world,themeleaf");
        return "1hello";
    }

    @GetMapping("/test2")
    public String test2(Model m)
    {
        m.addAttribute("username","张三");
        return "2string";
    }

    @GetMapping("/test3")
    public String test3(Model m,String flag)
    {
        m.addAttribute("flag",flag);
        return "3if";
    }

    @GetMapping("/test4")
    public String test4(Model m)
    {
        List<User> list = new ArrayList<>();
        list.add(new User("张三",18,"123456"));
        list.add(new User("张四",19,"123456"));
        list.add(new User("张三分",20,"123456"));

        m.addAttribute("list",list);

        return "4list";
    }

    @GetMapping("/test5")
    public  String test5(Model m)
    {

        m.addAttribute("type","link");
        m.addAttribute("pageId","springboot/2022/03/30/");
        m.addAttribute("img","https://fc5tn.baidu.com/it/u=188818894,1323916671&fm=202");
        return "5url";
    }


    @RequestMapping("/test6")
    public String test6(Model map) {
        map.addAttribute("sex", "woman");
        return "6switch";
    }


    @GetMapping("/test7")
    public String test7(Model m)
    {
        m.addAttribute("userName","张三");
        m.addAttribute("userId","15");
        return "7inline";
    }


    @GetMapping("/test8")
    public String test8()
    {
        System.out.println("test8");
        return "8index";
    }



    @GetMapping("/test9")
    public String test9()
    {
        System.out.println("test9");
        return "9fragment";
    }


    @GetMapping("/test10index")
    public String test10Index()
    {
        System.out.println("网站首页");
        return "10index";
    }

    @GetMapping("/test10user")
    public String test10User()
    {
        System.out.println("网站用户页");
        return "10user";
    }

}
